package com.itchen.hospital.controller;

import com.github.pagehelper.PageInfo;
import com.itchen.hospital.common.Result;
import com.itchen.hospital.pojo.Doctor;
import com.itchen.hospital.pojo.Params;
import com.itchen.hospital.service.DoctorService;
import com.itchen.hospital.service.DoctorService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/doctor")
@Tag(name = "医生信息接口")
@CrossOrigin
public class DoctorController {

    @Autowired
    private DoctorService doctorService;

    @GetMapping("/getAll")
    @Operation(summary = "查询所有")
    public Result findByAll() {
        List<Doctor> list = doctorService.getAll();
        return Result.success(list);
    }

    @GetMapping("/findBySearch")
    @Operation(summary = "条件查询")
    public Result findBySearch(Params params) {
        PageInfo<Doctor> list = doctorService.search(params);
        return Result.success(list);
    }

    @PostMapping("/add")
    @Operation(summary = "添加医生")
    public Result add(@RequestBody Doctor doctor) {
        doctorService.add(doctor);
        return Result.success();
    }

    //根据account回显
    @GetMapping("/findByAccount")
    @Operation(summary = "根据account回显")
    public Result findByDoctorInfo(String account) {
        Doctor doctor = doctorService.findByAccount(account);
        return Result.success(doctor);
    }

    @PostMapping("/update")
    @Operation(summary = "修改医生")
    public Result update(@RequestBody Doctor doctor) {
        doctorService.update(doctor);
        return Result.success();
    }

    @GetMapping("/delete")
    @Operation(summary = "删除医生")
    public Result delete(String account) {
        doctorService.delete(account);
        return Result.success();
    }

    @PostMapping("/batchDelete")
    @Operation(summary = "批量删除")
    public Result batchDelete(@RequestBody List<Doctor> doctors) {
        doctorService.batchDelete(doctors);
        return Result.success();
    }

}
